package leetcode.code0753;

import java.util.Deque;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Set;

import leetcode.IDebug;

public class Solution2 implements IDebug {
	
	
	Set<Integer> seen = new HashSet<Integer>();
    StringBuffer ans = new StringBuffer();
    int highest;
    int k;

    public String crackSafe(int n, int k) {
        highest = (int) Math.pow(10, n - 1);
        this.k = k;
        dfs(0);
        for (int i = 1; i < n; i++) {
            ans.append('0');
        }
        return ans.toString();
    }

    public void dfs(int node) {
        for (int x = 0; x < k; ++x) {
            int nei = node * 10 + x;
            if (!seen.contains(nei)) {
            	
                seen.add(nei);
                dfs(nei % highest);
                System.out.println("dfs" + nei % highest);
                System.out.println(node + " -> " + x);
                ans.append(x);
            }
        }
    }

	@Override
	public void debug4() {
		System.out.println(this.crackSafe(3, 3));

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution2 so = new Solution2();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();
		StringBuffer sb = new StringBuffer();
		Deque<Integer> queue = new LinkedList<>();
		queue.add(1);
		System.out.println("00222121112201202101102001000".length());
	}

}

